// Do file that conducts the analyses for the paper "Big Brother Sees You"


capture log close
log using "C:\Userdata\Shared\Logs\BigBrother/Replication.log", text replace 


use "D:\Data\ProjData\BigBrother/ReplicationData.dta", clear


*TABLE A1
*Descriptives
preserve

*Sample restrictions
keep if inrange(ValAlder, 18, 47)
keep if inrange(ValAr, 1998, 2014)
drop if DodDatum<19980901 & ValAr==1998
drop if DodDatum<20020901 & ValAr==2002
drop if DodDatum<20060901 & ValAr==2006
drop if DodDatum<20100901 & ValAr==2010
drop if DodDatum<20140901 & ValAr==2014

gen Kvinna = Kon-1

local sample "inrange(FodMorAntBarn, 2, 5) & inrange(UppMorAntBarn, 2, 5) & inrange(FodMorOrdNr, 1, 5) & inrange(UppMorOrdNr, 1, 5) & UtlSvBakG==22"
listwise NomKO ValdKO ListPlaceringKO UppMorOrdNr Kvinna ValAlder ValAr LopNrUppMor

sum NomKO ValdKO ListPlaceringKO Kvinna FodAr UtbAr UppMorAntBarn UppMorFodAr UppMorUtbAr if `sample'

qui reg NomKO i.UppMorAntBarn if `sample'
gen bN3 = _b[3.UppMorAntBarn]
gen bN4 = _b[4.UppMorAntBarn]
gen bN5 = _b[5.UppMorAntBarn]
gen occNomKO = NomKO
replace occNomKO = occNomKO-bN3 if UppMorAntBarn==3
replace occNomKO = occNomKO-bN4 if UppMorAntBarn==4
replace occNomKO = occNomKO-bN5 if UppMorAntBarn==5

qui reg ValdKO i.UppMorAntBarn if `sample'
gen bV3 = _b[3.UppMorAntBarn]
gen bV4 = _b[4.UppMorAntBarn]
gen bV5 = _b[5.UppMorAntBarn]
gen occValdKO = ValdKO
replace occValdKO = occValdKO-bV3 if UppMorAntBarn==3
replace occValdKO = occValdKO-bV4 if UppMorAntBarn==4
replace occValdKO = occValdKO-bV5 if UppMorAntBarn==5

qui reg ListPlaceringKO i.UppMorAntBarn if `sample'
gen bL3 = _b[3.UppMorAntBarn]
gen bL4 = _b[4.UppMorAntBarn]
gen bL5 = _b[5.UppMorAntBarn]
gen occListPlaceringKO = ListPlaceringKO
replace occListPlaceringKO = occListPlaceringKO-bL3 if UppMorAntBarn==3
replace occListPlaceringKO = occListPlaceringKO-bL4 if UppMorAntBarn==4
replace occListPlaceringKO = occListPlaceringKO-bL5 if UppMorAntBarn==5

sum occNomKO occValdKO occListPlaceringKO if `sample'
sum occNomKO occValdKO occListPlaceringKO if `sample' & UppMorOrdNr==2
sum occNomKO occValdKO occListPlaceringKO if `sample' & UppMorOrdNr==3
sum occNomKO occValdKO occListPlaceringKO if `sample' & UppMorOrdNr==4
sum occNomKO occValdKO occListPlaceringKO if `sample' & UppMorOrdNr==5


bysort LopNrUppMor: egen withinNomKO = max(NomKO)
bysort LopNrUppMor: egen withinValdKO = max(ValdKO)
bysort LopNrUppMor: egen withinListPlaceringKO = max(ListPlaceringKO)

sum NomKO Kvinna FodAr UtbAr UppMorAntBarn UppMorFodAr UppMorUtbAr if `sample' & withinNomKO!=0
sum ValdKO Kvinna FodAr UtbAr UppMorAntBarn UppMorFodAr UppMorUtbAr if `sample' & withinValdKO!=0
sum ListPlaceringKO Kvinna FodAr UtbAr UppMorAntBarn UppMorFodAr UppMorUtbAr if `sample' & withinListPlaceringKO!=0
restore



*********
*RESULTS*
*********

preserve
*Sample restrictions
keep if inrange(ValAlder, 18, 47)
keep if inrange(ValAr, 1998, 2014)
drop if DodDatum<19980901 & ValAr==1998
drop if DodDatum<20020901 & ValAr==2002
drop if DodDatum<20060901 & ValAr==2006
drop if DodDatum<20100901 & ValAr==2010
drop if DodDatum<20140901 & ValAr==2014
keep if inrange(FodMorAntBarn, 2, 5)
keep if inrange(UppMorAntBarn, 2, 5)
keep if inrange(FodMorOrdNr, 1, 5)
keep if inrange(UppMorOrdNr, 1, 5)
keep if UtlSvBakG==22
replace Kon = Kon-1



local controls "Kon i.ValAlder i.ValAr"


sum NomKO if `sample' & UppMorOrdNr == 1
sum NomKO if `sample' & UppMorOrdNr == 2
sum NomKO if `sample' & UppMorOrdNr == 3
sum NomKO if `sample' & UppMorOrdNr == 4
sum NomKO if `sample' & UppMorOrdNr == 5

sum ValdKO if `sample' & UppMorOrdNr == 1
sum ValdKO if `sample' & UppMorOrdNr == 2
sum ValdKO if `sample' & UppMorOrdNr == 3
sum ValdKO if `sample' & UppMorOrdNr == 4
sum ValdKO if `sample' & UppMorOrdNr == 5

sum ListPlaceringKO if `sample' & UppMorOrdNr == 1
sum ListPlaceringKO if `sample' & UppMorOrdNr == 2
sum ListPlaceringKO if `sample' & UppMorOrdNr == 3
sum ListPlaceringKO if `sample' & UppMorOrdNr == 4
sum ListPlaceringKO if `sample' & UppMorOrdNr == 5


*Baseline - TABLE 1 AND TABLE A4
areg NomKO i.UppMorOrdNr `controls', absorb(LopNrUppMor) cluster(LopNrUppMor)
test 2.UppMorOrdNr = 3.UppMorOrdNr
test 2.UppMorOrdNr = 4.UppMorOrdNr
test 2.UppMorOrdNr = 5.UppMorOrdNr
test 3.UppMorOrdNr = 4.UppMorOrdNr
test 3.UppMorOrdNr = 5.UppMorOrdNr
test 4.UppMorOrdNr = 5.UppMorOrdNr
areg NomKO i.UppMorOrdNr i.FodMorOrdNr `controls', absorb(LopNrUppMor) cluster(LopNrUppMor)
sum NomKO if e(sample)
areg ValdKO i.UppMorOrdNr `controls', absorb(LopNrUppMor) cluster(LopNrMor)
test 2.UppMorOrdNr = 3.UppMorOrdNr
test 2.UppMorOrdNr = 4.UppMorOrdNr
test 2.UppMorOrdNr = 5.UppMorOrdNr
test 3.UppMorOrdNr = 4.UppMorOrdNr
test 3.UppMorOrdNr = 5.UppMorOrdNr
test 4.UppMorOrdNr = 5.UppMorOrdNr
areg ValdKO i.UppMorOrdNr i.FodMorOrdNr `controls', absorb(LopNrUppMor) cluster(LopNrMor)
sum ValdKO if e(sample)
areg ListPlaceringKO i.UppMorOrdNr `controls', absorb(LopNrUppMor) cluster(LopNrMor)
test 2.UppMorOrdNr = 3.UppMorOrdNr
test 2.UppMorOrdNr = 4.UppMorOrdNr
test 2.UppMorOrdNr = 5.UppMorOrdNr
test 3.UppMorOrdNr = 4.UppMorOrdNr
test 3.UppMorOrdNr = 5.UppMorOrdNr
test 4.UppMorOrdNr = 5.UppMorOrdNr
areg ListPlaceringKO i.UppMorOrdNr i.FodMorOrdNr `controls', absorb(LopNrUppMor) cluster(LopNrMor)
sum ListPlaceringKO if e(sample)


*TABLE A5
*Number of families in which the biological and social birth orders differ
*Baseline results in this restricted sample
gen occ = UppMorOrdNr - FodMorOrdNr
replace occ = . if occ==0
bysort LopNrUppMor: egen nocc = total(occ), missing
bysort LopNrUppMor: gen mocc = _n

qui: areg NomKO i.UppMorOrdNr i.FodMorOrdNr `controls', absorb(LopNrUppMor) cluster(LopNrUppMor)

sum nocc if mocc==1 & e(sample)
sum mocc if mocc==1 & e(sample)

areg NomKO i.UppMorOrdNr `controls' if nocc!=., absorb(LopNrUppMor) cluster(LopNrUppMor)
areg NomKO i.UppMorOrdNr i.FodMorOrdNr `controls' if nocc!=., absorb(LopNrUppMor) cluster(LopNrUppMor)
sum NomKO if e(sample)
areg ValdKO i.UppMorOrdNr `controls' if nocc!=., absorb(LopNrUppMor) cluster(LopNrUppMor)
areg ValdKO i.UppMorOrdNr i.FodMorOrdNr `controls' if nocc!=., absorb(LopNrUppMor) cluster(LopNrUppMor)
sum ValdKO if e(sample)
areg ListPlaceringKO i.UppMorOrdNr `controls' if nocc!=., absorb(LopNrUppMor) cluster(LopNrUppMor)
areg ListPlaceringKO i.UppMorOrdNr i.FodMorOrdNr `controls' if nocc!=., absorb(LopNrUppMor) cluster(LopNrUppMor)
sum ListPlaceringKO if e(sample)

tab UppMorOrdNr FodMorOrdNr if e(sample)


*TABLE A13
*Conditional on being nominated
areg ValdKO i.UppMorOrdNr `controls' if NomKO==100, absorb(LopNrUppMor) cluster(LopNrMor)
sum ValdKO if e(sample)
areg ListPlaceringKO i.UppMorOrdNr `controls' if NomKO==100, absorb(LopNrUppMor) cluster(LopNrMor)
sum ListPlaceringKO if e(sample)


*TABLE A3
*Compare effect sizes - use dummy for sex and college
gen HogExam = .
replace HogExam = 0 if inrange(UtbAr, 7, 14)
replace HogExam = 1 if inrange(UtbAr, 15, 19)

areg NomKO i.UppMorOrdNr HogExam `controls', absorb(LopNrUppMor) cluster(LopNrMor)
sum NomKO if e(sample)
areg ValdKO i.UppMorOrdNr HogExam `controls', absorb(LopNrUppMor) cluster(LopNrMor)
sum ValdKO if e(sample)
areg ListPlaceringKO i.UppMorOrdNr HogExam `controls', absorb(LopNrUppMor) cluster(LopNrMor)
sum ListPlaceringKO if e(sample)


*TABLES A10, A11 AND A12
*By family size
areg NomKO i.UppMorOrdNr `controls' if inrange(UppMorAntBarn, 2, 2), absorb(LopNrUppMor) cluster(LopNrUppMor)
sum NomKO if e(sample)
areg NomKO i.UppMorOrdNr `controls' if inrange(UppMorAntBarn, 3, 3), absorb(LopNrUppMor) cluster(LopNrUppMor)
sum NomKO if e(sample)
areg NomKO i.UppMorOrdNr `controls' if inrange(UppMorAntBarn, 4, 4), absorb(LopNrUppMor) cluster(LopNrUppMor)
sum NomKO if e(sample)
areg NomKO i.UppMorOrdNr `controls' if inrange(UppMorAntBarn, 5, 5), absorb(LopNrUppMor) cluster(LopNrUppMor)
sum NomKO if e(sample)

areg ValdKO i.UppMorOrdNr `controls' if inrange(UppMorAntBarn, 2, 2), absorb(LopNrUppMor) cluster(LopNrUppMor)
sum ValdKO if e(sample)
areg ValdKO i.UppMorOrdNr `controls' if inrange(UppMorAntBarn, 3, 3), absorb(LopNrUppMor) cluster(LopNrUppMor)
sum ValdKO if e(sample)
areg ValdKO i.UppMorOrdNr `controls' if inrange(UppMorAntBarn, 4, 4), absorb(LopNrUppMor) cluster(LopNrUppMor)
sum ValdKO if e(sample)
areg ValdKO i.UppMorOrdNr `controls' if inrange(UppMorAntBarn, 5, 5), absorb(LopNrUppMor) cluster(LopNrUppMor)
sum ValdKO if e(sample)

areg ListPlaceringKO i.UppMorOrdNr `controls' if inrange(UppMorAntBarn, 2, 2), absorb(LopNrUppMor) cluster(LopNrUppMor)
sum ListPlaceringKO if e(sample)
areg ListPlaceringKO i.UppMorOrdNr `controls' if inrange(UppMorAntBarn, 3, 3), absorb(LopNrUppMor) cluster(LopNrUppMor)
sum ListPlaceringKO if e(sample)
areg ListPlaceringKO i.UppMorOrdNr `controls' if inrange(UppMorAntBarn, 4, 4), absorb(LopNrUppMor) cluster(LopNrUppMor)
sum ListPlaceringKO if e(sample)
areg ListPlaceringKO i.UppMorOrdNr `controls' if inrange(UppMorAntBarn, 5, 5), absorb(LopNrUppMor) cluster(LopNrUppMor)
sum ListPlaceringKO if e(sample)


*TABLE A7
*By sex
areg NomKO i.UppMorOrdNr##c.Kon `controls', absorb(LopNrUppMor) cluster(LopNrMor)
sum NomKO if e(sample)

areg ValdKO i.UppMorOrdNr##c.Kon `controls', absorb(LopNrUppMor) cluster(LopNrMor)
sum ValdKO if e(sample)

areg ListPlaceringKO i.UppMorOrdNr##c.Kon `controls', absorb(LopNrUppMor) cluster(LopNrMor)
sum ListPlaceringKO if e(sample)


*FIGURE 1, A1 AND A2 AND TABLE A6
*Mechanisms - education/occupation and cognitive/non-cognitive abilities
areg NomKO i.UppMorOrdNr `controls' i.IQ i.PF i.Sun2000niva i.UtbInr i.SSYK4 if Kon==0, absorb(LopNrUppMor) cluster(LopNrUppMor)
areg NomKO i.UppMorOrdNr `controls' if e(sample), absorb(LopNrUppMor) cluster(LopNrUppMor)
sum NomKO if e(sample)

areg ValdKO i.UppMorOrdNr `controls' i.IQ i.PF i.Sun2000niva i.UtbInr i.SSYK4 if Kon==0, absorb(LopNrUppMor) cluster(LopNrUppMor)
areg ValdKO i.UppMorOrdNr `controls' if e(sample), absorb(LopNrUppMor) cluster(LopNrUppMor)
sum ValdKO if e(sample)

areg ListPlaceringKO i.UppMorOrdNr `controls' i.IQ i.PF i.Sun2000niva i.UtbInr i.SSYK4 if Kon==0, absorb(LopNrUppMor) cluster(LopNrUppMor)
areg ListPlaceringKO i.UppMorOrdNr `controls' if e(sample), absorb(LopNrUppMor) cluster(LopNrUppMor)
sum ListPlaceringKO if e(sample)


restore



*No age restrictions
preserve
use "D:\Data\ProjData\BigBrother/BigBrotherData.dta", clear
*Sample restrictions
keep if inrange(ValAlder, 18, 100)
*keep if inrange(ValAr, 1998, 2014)
drop if DodDatum<19820901 & ValAr==1982
drop if DodDatum<19850901 & ValAr==1985
drop if DodDatum<19880901 & ValAr==1988
drop if DodDatum<19910901 & ValAr==1991
drop if DodDatum<19940901 & ValAr==1994
drop if DodDatum<19980901 & ValAr==1998
drop if DodDatum<20020901 & ValAr==2002
drop if DodDatum<20060901 & ValAr==2006
drop if DodDatum<20100901 & ValAr==2010
drop if DodDatum<20140901 & ValAr==2014


local controls "Kon i.ValAlder i.ValAr"
local sample "inrange(FodMorAntBarn, 2, 5) & inrange(UppMorAntBarn, 2, 5) & inrange(FodMorOrdNr, 1, 5) & inrange(UppMorOrdNr, 1, 5) & UtlSvBakG==22"


*TABLE A8
*Baseline - no restrictions on age
areg NomKO i.UppMorOrdNr `controls' if `sample' & inrange(ValAr, 1998, 2014), absorb(LopNrUppMor) cluster(LopNrUppMor)
sum NomKO if e(sample)
areg ValdKO i.UppMorOrdNr `controls' if `sample' & inrange(ValAr, 1998, 2014), absorb(LopNrUppMor) cluster(LopNrUppMor)
sum ValdKO if e(sample)
areg ListPlaceringKO i.UppMorOrdNr `controls' if `sample' & inrange(ValAr, 1998, 2014), absorb(LopNrUppMor) cluster(LopNrUppMor)
sum ListPlaceringKO if e(sample)


*TABLE A9
*Baseline - no restrictions on age or number of elections
areg NomKO i.UppMorOrdNr `controls' if `sample', absorb(LopNrUppMor) cluster(LopNrUppMor)
sum NomKO if e(sample)
areg ValdKO i.UppMorOrdNr `controls' if `sample', absorb(LopNrUppMor) cluster(LopNrUppMor)
sum ValdKO if e(sample)
areg ListPlaceringKO i.UppMorOrdNr `controls' if `sample' & ValAr!=1991, absorb(LopNrUppMor) cluster(LopNrUppMor)
sum ListPlaceringKO if e(sample)

restore

preserve
*Sample restrictions
keep if inrange(ValAlder, 18, 47)
keep if inrange(ValAr, 1998, 2014)
drop if DodDatum<19980901 & ValAr==1998
drop if DodDatum<20020901 & ValAr==2002
drop if DodDatum<20060901 & ValAr==2006
drop if DodDatum<20100901 & ValAr==2010
drop if DodDatum<20140901 & ValAr==2014


local controls "Kon i.ValAlder i.ValAr"
local sample "inrange(FodMorAntBarn, 2, 5) & inrange(UppMorAntBarn, 2, 5) & inrange(FodMorOrdNr, 1, 5) & inrange(UppMorOrdNr, 1, 5) & UtlSvBakG==22"


*TABLE A2
*Baseline
clogit NomKO i.UppMorOrdNr `controls' if `sample', group(LopNrUppMor) cluster(LopNrUppMor)
margins, dydx(UppMorOrdNr*) predict(pu0)
sum NomKO if e(sample)

clogit ValdKO i.UppMorOrdNr `controls' if `sample', group(LopNrUppMor) cluster(LopNrUppMor)
margins, dydx(UppMorOrdNr*) predict(pu0)
sum ValdKO if e(sample)

clogit ListPlaceringKO i.UppMorOrdNr `controls' if `sample', group(LopNrUppMor) cluster(LopNrUppMor)
margins, dydx(UppMorOrdNr*) predict(pu0)
sum ListPlaceringKO if e(sample)


restore


log close

